package com.mall507.fivepeaks.comn.itemDecoration;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.hzh.frame.BaseInitData;
import com.hzh.frame.widget.xrecyclerview.BaseRecyclerAdapter;
import com.mall507.fivepeaks.R;
import com.mall507.fivepeaks.comn.config.Constant;

/**
 * @author：admin on 2017/4/7 10:43.
 */

public class ShopMainItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private int itemFirstPosition = -1;
    private Paint bgPint;

    public ShopMainItemDecoration(int space) {
        this.space = space;
        this.bgPint=new Paint();
        this.bgPint.setColor(ContextCompat.getColor(BaseInitData.applicationContext,R.color.comn_bg));
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int itemPosition = parent.getChildLayoutPosition(view);
        switch (parent.getAdapter().getItemViewType(itemPosition)){
            case BaseRecyclerAdapter.TYPE_HEADER:
                break;
            case BaseRecyclerAdapter.TYPE_FOOTER:
                break;
            case Constant.TYPE_SHOP_ITEM://这里BaseRecyclerAdapter的setItemChildViewType被ShopMainAdapter重写了,故BaseRecyclerAdapter.TYPE_NORMAL被细分成了很多个类型
                if(itemPosition!=parent.getAdapter().getItemCount()-1){
                    outRect.bottom= 5;
                }
                break;
        }
    }

    @Override
    public void onDrawOver(Canvas c,RecyclerView parent,RecyclerView.State state) {
        super.onDrawOver(c, parent, state);
        int childCount = parent.getChildCount();
        for(int i=0;i<childCount;i++){
            View view=parent.getChildAt(i);
            int position=parent.getChildPosition(view);
            switch (parent.getAdapter().getItemViewType(position)){
                case BaseRecyclerAdapter.TYPE_HEADER:
                    break;
                case BaseRecyclerAdapter.TYPE_FOOTER:
                    break;
                case Constant.TYPE_SHOP_ITEM:
                    c.drawRect(view.getLeft(),view.getBottom(),view.getRight(),view.getBottom()+5,bgPint);
                    break;
            }
        }
    }
}
